package main;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.text.Format;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.border.EmptyBorder;

import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.Barcode39;
import com.lowagie.text.pdf.BaseFont;

import com.lowagie.text.pdf.PdfWriter;

import commans.ChangeCode;
import commans.ErrorPage;

import java.io.BufferedReader;

public  class CreatePolicyMain extends JFrame implements Serializable,
        Runnable
{

    // Input Output File Mode
    public File fileA = null;
    public File fileW = null;
    public FileWriter fw1 = null;
    public FileWriter fw2 = null;
    public InputStreamReader isr = null;
    public BufferedReader br = null;
    public InputStreamReader isrA = null;
    public BufferedReader brA = null;
    public InputStreamReader isrW = null;
    public BufferedReader brW = null;
    // iText Mode
    public PdfWriter writer = null;
    public Document document = new Document();
    public Image jpeg = null;
    public Barcode39 code39 = new Barcode39();
    public String str1 = null , str2 = null , str4 = null , str5 = null ,
	  str6 = null;
    public String Line = null , line1 = null , line2 = null , line3 = null ,
	  line4 = null , line5 = null , line6 = null;
    public String Pkind = null;
    public File ROOT = new File("C:\\");
    public BaseFont bfChinese;
    // File Name
    public String path = null;
    public String broker = null;
    public int commit = 0;
    public Runtime rt = Runtime.getRuntime();
    // New function
    public ChangeCode function = new ChangeCode();
    // OpenFile Mode
    public JFileChooser fc = new JFileChooser();
    public int ret = 1;
    // Program Attribute
    public String row[] = new String[150];
    public String str3[] = new String[20];
    public int num1 = 0;
    public int num2 = 0;
    public int checkAMT = 0;
    // ProgressBar Mode
    public JProgressBar progressBar = new JProgressBar();
    public JPanel contentPane;
    public int currentValue;
    public int count;
    public long totalBytes = 0;
    public long byteRead = 0;

    public CreatePolicyMain()
    {
        setTitle("Progress");
        setResizable(false);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setBounds(100,100,326,122);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5,5,5,5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
        setLocationRelativeTo(null); // 視窗至中
        progressBar.setBounds(14,34,290,21);
        // 設置初始值與最大值
        progressBar.setStringPainted(true);
        progressBar.setValue(0);
        progressBar.setMaximum(100);
        contentPane.add(progressBar);
        JLabel lblNewLabel = new JLabel("\u7522\u751F\u4E2D...........");
        lblNewLabel.setBounds(56,13,217,19);
        contentPane.add(lblNewLabel);
    }
    protected void deleteFile(String path)
    {
        File deleteFile;
        deleteFile = new File(path);
        deleteFile.delete();
    }
    protected void deleteFile(File obj)
    {
        File deleteFile;
        deleteFile = obj;
        deleteFile.delete();
        if(obj.delete())
        {
	  System.out.println("Cant Delete File!");
        }
    }
    protected void ErrorMessage(Throwable T)
    {
        new ErrorPage(T);
    }
    protected static String MakesUpSpace(String str, int lenSize)
    {

        String space = "　";// 全形空白
        str = str.replaceAll("　",""); // 取代全形空白為""
        str = str.replaceAll(" ",""); // 取代半形空白為""
        String returnValue = null;
        returnValue = str;
        for(int i = 0; i<lenSize; i++)
        {
	  returnValue = returnValue+space;
        }

        return returnValue.substring(0,lenSize);//

    }

    protected static String MakesUpSpace2(String str, int lenSize)
    {

        String space = " ";// 半形空白
        str = str.replaceAll("　",""); // 取代全形空白為""
        str = str.replaceAll(" ",""); // 取代半形空白為""
        String returnValue = null;
        returnValue = str;
        for(int i = 0; i<lenSize; i++)
        {
	  returnValue = returnValue+space;
        }
        return returnValue;// 取0到9碼
    }

    // 其他險代號如果為00就去掉
    protected static String CutPolicyNumber(String str)
    {

        if(str.equals("00"))
        {
	  str = "  ";
        }
        else
        {
	  str = str;
        }
        return str;// 取0到9碼
    }

    // 金額前面為0的部分去掉//金額等於0就不顯示
    protected static String CatZero(String str)
    {

        char[] charArr = str.toCharArray();
        int i = 0;
        String Newstr = "";
        for(i = 0; i<charArr.length; i++)
        {
	  if(charArr[i]=='0')
	  {
	      charArr[i] = ' ';
	  }
	  else
	  {
	      break;
	  }
        }
        for(i = 0; i<charArr.length; i++)
        {
	  Newstr = Newstr+charArr[i];
        }
        Newstr = Newstr.replaceAll(" ","");// 去半形空白
        Newstr = Newstr.replaceAll("　","");// 去全行空白
        // 轉換成千分位
        Format fm = new DecimalFormat();
        double Mnoey;
        try
        {
	  Mnoey = Integer.parseInt(Newstr);
	  Newstr = fm.format(Mnoey);
        }
        catch (NumberFormatException e)
        {

        }
        return Newstr;// 取0到9碼
    }

    @Override
    public void run()
    {
        //實作印表
        
    }
}
